package next.ControllerResponsibilities;

import next.TemplateActivity.R;
import next.control.ApplicationController;
import next.control.ApplicationController.TypeUser;
import next.control.support.BetterPopupWindow;
import next.control.support.DemoPopupWindow;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.Toast;
import next.Functionality.S_3R4_Activity;
import next.Functionality.SmsFunctionality.TypeSMS;

public class ApplicationControllerListener implements
		android.view.View.OnClickListener {

	private Bundle b;
	public static final int VOICE_ACTIVITY = 1;
	private View LastView;
	

	public ApplicationControllerListener(Bundle b2) {
		super();
		this.b = b2;
	}

	@Override
	public void onClick(View v) {
			
		// --TITLE WIDGET The profile actions close everything up to
		// PROFILE*********************
		// --PROFILE ACTIONS
		/** GO PROFILE */
		if (v.getId() == R.id.title_widgetBTN01) {
			if (!ApplicationController.PROFILE()) {
				ApplicationController.GOPROFILE = true;
				((Activity) v.getContext()).finish();
			} else
				Toast.makeText(v.getContext(), "You are currently in Profile",
						Toast.LENGTH_SHORT).show();
		}

		// --MESSAGE ACTIONS
		/** NEW MESSAGE */
		else if (v.getId() == R.id.BTN_Order1) {
			ApplicationController.OrderWin.dismiss();
			
			String[] s = { "a@gmail.com", "b@gmail.com" };
			((S_3R4_Activity) v.getContext()).CreateSMS(TypeSMS.CUSTOM, s,
					"mensaje", "kiquened85@gmail.com");
			
		}
		/** CHECK MESSAGES */
		else if (v.getId() == R.id.BTN_Order2) {
			
			ApplicationController.OrderWin.dismiss();
		}/** NEW ORDER */
		else if (v.getId() == R.id.BTN_Order3) {
     		String where = v.getContext().getResources()
					.getString(R.string.AN_NEW_ORDER);
			ApplicationController.OrderWin.dismiss();
			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				((Activity) v.getContext()).startActivity(i);
			} 
		}/** CHECK ORDER */
		else if (v.getId() == R.id.BTN_Order4) {
		
			ApplicationController.OrderWin.dismiss();
		}

		// --PREFERENCES ACTIONS*/
		/** NEW SON */
		if (v.getId() == R.id.BTN_Preference1) {
			
			ApplicationController.PreferenceWin.dismiss();
		}/**Voice Recognition */
		else if (v.getId() == R.id.BTN_Preference2) {
			
			ApplicationController.PreferenceWin.dismiss();
			
			String where = v.getContext().getResources()
					.getString(R.string.AN_List_1);
			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				((Activity) v.getContext()).startActivity(i);
			}
		}/** */
		else if (v.getId() == R.id.BTN_Preference3) {
			
			ApplicationController.PreferenceWin.dismiss();
		}/** */
		else if (v.getId() == R.id.BTN_Preference4) {
			
			ApplicationController.PreferenceWin.dismiss();
		}/** */
		else if (v.getId() == R.id.BTN_Preference5) {

			ApplicationController.PreferenceWin.dismiss();
		}/** */
		else if (v.getId() == R.id.BTN_Preference6) {

			ApplicationController.PreferenceWin.dismiss();
		}

		// --SEARCH OPTIONS
		/** LIST ENTERPRISES */
		else if (v.getId() == R.id.BTN_Search1) {

			ApplicationController.SearchWin.dismiss();
			String where = v.getContext().getResources()
					.getString(R.string.AN_SEARCH_ENTERPRISES);
			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				v.getContext().startActivity(i);
			}
			
		}/** */
		else if (v.getId() == R.id.BTN_Search2) {
			ApplicationController.SearchWin.dismiss();

		}/** */
		else if (v.getId() == R.id.BTN_Search3) {
			ApplicationController.SearchWin.dismiss();
		}/** */
		else if (v.getId() == R.id.BTN_Search4) {
			ApplicationController.SearchWin.dismiss();
		}/** */
		else if (v.getId() == R.id.BTN_Search5) {
			ApplicationController.SearchWin.dismiss();
		}/** */
		else if (v.getId() == R.id.BTN_Search6) {
			ApplicationController.SearchWin.dismiss();
		}

		// --LIST_ACTIVITY_OPTIONS*********************************************
		/** Voice=(Button)findViewById(R.id.generic_list_custom_BN1) */
		else if (v.getId() == R.id.generic_list_custom_BN1) {
			String where = v.getContext().getResources()
					.getString(R.string.AN_List_1);
			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				((Activity) v.getContext()).startActivity(i);
			}
		}
		/** Voice=(Button)findViewById(R.id.generic_list_custom_BN4) */
		else if (v.getId() == R.id.generic_list_custom_BN4) {
			String where = v.getContext().getResources()
					.getString(R.string.AN_List_4);
			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				((Activity) v.getContext()).startActivity(i);
			}
		}
		
		// --DASHBOARD_PRINCIPAL*********************************************
		/** BTN_MSI = (Button) findViewById(R.id.dashboard_principalBTN04); */
		else if (v.getId() == R.id.dashboard_principalBTN04) {
			String where = v.getContext().getResources()
					.getString(R.string.AN_DSI);
			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				b.putInt("TypeUser", 2);
				i.putExtras(b);
				v.getContext().startActivity(i);
			}

			/**
			 * BTN_ASU = (Button) findViewById(R.id.dashboard_principalBTN01);
			 * BTN_CSU = (Button) findViewById(R.id.dashboard_principalBTN02);
			 */
		} else if (v.getId() == R.id.dashboard_principalBTN01
				|| v.getId() == R.id.dashboard_principalBTN02) {

			String where = v.getContext().getResources()
					.getString(R.string.AN_DSU);
			if (v.getId() == R.id.dashboard_principalBTN01)
				ApplicationController.setCurrentUser(TypeUser.ADMIN);
			else
				ApplicationController.setCurrentUser(TypeUser.CLIENT);

			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				b.putInt("TypeUser", 1);
				i.putExtras(b);
				((S_3R4_Activity) v.getContext()).startActivityForResult(i, 1);
			}
			/**
			 * BTN_Search = (Button)
			 * findViewById(R.id.dashboard_principalBTN06);
			 */
		} else if (v.getId() == R.id.dashboard_principalBTN06) {
			String where = v.getContext().getResources()
					.getString(R.string.AN_DSU);
			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				b.putInt("TypeUser", 1);
				i.putExtras(b);
				((S_3R4_Activity) v.getContext()).startActivityForResult(i, 1);
			}
		}

		// --DASHBOARD_SIGN IN*********************************************
		/** okSI = (Button) findViewById(R.id.dashboard_sign_inBN01); */
		else if (v.getId() == R.id.dashboard_sign_inBN01) {
			String where = v.getContext().getResources()
					.getString(R.string.AN_A_PRINCIPAL);
			/*
			 * if (currentUser==TypeUser.ADMIN){
			 * where="next.Admin.Admin_Principal"; } else if
			 * (currentUser==TypeUser.ADMIN){
			 * where="next.Client.Client_Principal"; } else
			 * where="next.Member.Member_Principal";
			 */
			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				b.putInt("TypeUser", 1);
				i.putExtras(b);
				v.getContext().startActivity(i);
			}
		}
		// --ADMIN PROFILE**************************************************
		/** PI=(Button) findViewById(R.id.admin_principalBTN01); PERSONAL INFO */
		else if (v.getId() == R.id.admin_principalBTN01) {
			String where = v.getContext().getResources()
					.getString(R.string.AN_PERSONAL_INFO);

			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				v.getContext().startActivity(i);
			}
		}
		/** LI=(Button) findViewById(R.id.admin_principalBTN02); */
		else if (v.getId() == R.id.admin_principalBTN02) {
			String where = new String("");

			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				v.getContext().startActivity(i);
			}
		}
		/** SI=(Button) findViewById(R.id.admin_principalBTN03); */
		else if (v.getId() == R.id.admin_principalBTN03) {
			String where = new String("");

			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				v.getContext().startActivity(i);
			}
		}
		/** StatusI=(Button) findViewById(R.id.admin_principalBTN04); */
		else if (v.getId() == R.id.admin_principalBTN04) {
			String where = new String("");

			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				v.getContext().startActivity(i);
			}
		}
		/** BR=(Button) findViewById(R.id.admin_principalBTN05); BUSINESS RULES */
		else if (v.getId() == R.id.admin_principalBTN05) {
			String where = v.getContext().getResources()
					.getString(R.string.AN_A_BUSINESSRULES);

			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				v.getContext().startActivity(i);
			}
		}
		/** AP=(Button) findViewById(R.id.admin_principalBTN06); */
		else if (v.getId() == R.id.admin_principalBTN06) {
			String where = new String("");

			if (ApplicationController.GO(where)) {
				Intent i = new Intent(where);
				v.getContext().startActivity(i);
			}
		}

		// --PERSONAL INFO**************************************************
		/** save = (Button)findViewById(R.id.common_Personal_InfoBTN01); */
		else if (v.getId() == R.id.common_Personal_InfoBTN01) {
			((S_3R4_Activity) v.getContext()).finish();
		}

		// --BUSINESS RULES**************************************************
		/** */
		else if (v.getId() == R.id.common_Personal_InfoBTN01) {

		}
	}

	
}
